package cn.com.code.generator.utils;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * 代码生成器   工具类
 */
@Component
public class GenSystemUtils extends AbstractGenUtils{

    /**
     * 获取文件名
     */
    @Override
    public String getFileName(String template, String className, String packageName, String moduleName) {
        String classname = className.substring(0, 1).toLowerCase() + className.substring(1);

        String packagePath = "main" + File.separator + "java" + File.separator;
        if (StringUtils.isNotBlank(packageName)) {
            packagePath += packageName.replace(".", File.separator) + File.separator + moduleName + File.separator;
        }

        if (template.contains("Entity.java.vm" )) {
            return  "backend" + File.separator + "model" + File.separator + "src"  + File.separator + packagePath + "entity" + File.separator + className + ".java";
        }

        if (template.contains("Dao.java.vm" )) {
            return "backend" + File.separator + "web" + File.separator + "src"  + File.separator + packagePath + "dao" + File.separator + className + "Dao.java";
        }

        if (template.contains("Service.java.vm" )) {
            return "backend" + File.separator + "web" + File.separator + "src"  + File.separator + packagePath + "service" + File.separator + className + "Service.java";
        }

        if (template.contains("ServiceImpl.java.vm" )) {
            return "backend" + File.separator + "web" + File.separator + "src"  + File.separator + packagePath + "service" + File.separator + "impl" + File.separator + className + "ServiceImpl.java";
        }

        if (template.contains("Controller.java.vm" )) {
            return "backend" + File.separator + "web" + File.separator + "src"  + File.separator + packagePath + "controller" + File.separator + className + "Controller.java";
        }

        if (template.contains("Dao.xml.vm" )) {
            return "backend" + File.separator + "web" + File.separator + "src" + File.separator + "main" + File.separator + "resources" + File.separator + "mapper" + File.separator + moduleName + File.separator + className + "Dao.xml";
        }

        if (template.contains("menu.mysql.sql.vm" )) {
            return "backend" + File.separator + className.toLowerCase() + "_menu_mysql.sql";
        }
        if (template.contains("menu.oracle.sql.vm" )) {
            return "backend" + File.separator + className.toLowerCase() + "_menu_oracle.sql";
        }

        if (template.contains("index.vue.vm" )) {
            return "frontend" + File.separator + "src" + File.separator + "views" + File.separator + "admin" + File.separator + "systemManage" +
                    File.separator + className.toLowerCase() + File.separator + "index.vue";
        }

        if (template.contains("add.vue.vm" )) {
            return "frontend" + File.separator + "src" + File.separator + "views" + File.separator + "admin" + File.separator + "systemManage" +
                    File.separator + className.toLowerCase() + File.separator +"add" + className +".vue";
        }

        if (template.contains("detail.vue.vm" )) {
            return "frontend" + File.separator + "src" + File.separator + "views" + File.separator + "admin" + File.separator + "systemManage" +
                    File.separator + className.toLowerCase() + File.separator + classname +"Detail.vue";
        }

        if (template.contains("index.js.vm" )) {
            return "frontend" + File.separator + "index.js";
        }

        if (template.contains("api.js.vm" )) {
            return "frontend" + File.separator + "api.js";
        }

        return null;
    }
}
